//
//  ZLWrongParsingSheetCell.m
//  ZLExamination
//
//  Created by Zheng on 2017/9/13.
//  Copyright © 2017年 Zheng. All rights reserved.
//

#import "ZLWrongParsingSheetCell.h"
#import "ZLExamResultModel.h"


@implementation ZLWrongParsingSheetCell

#pragma mark - 点击事件
- (void)buttonClickAction:(UIButton *)sender {
    if (_clickCallBack) {
        _clickCallBack(sender.tag-30000);
    }
}

#pragma mark - 初始化
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    return self;
}

- (void)setNumbersWithRows:(NSInteger)rows withSingles:(NSArray *)singles {
    for (int i = 0; i< rows; i++) {
        
        UIView *bgView = [[UIView alloc] init];
        bgView.backgroundColor = [UIColor whiteColor];
        CGFloat a = i/5.;
        NSInteger b = i/5+1;
        NSInteger row = a>b? b: b-1;
        
        bgView.frame = CGRectMake(kSCREEN_WIDTH/5*(i%5), kSCREEN_WIDTH/5*row, kSCREEN_WIDTH/5, kSCREEN_WIDTH/5);
        [self.contentView addSubview:bgView];
        
        UIButton *numberBtn;
        
        ZLExamResultListModel *model = (ZLExamResultListModel *)singles[i];
        
        numberBtn = [self getNumberLblWithType:model.typeOfAnswer];
        
        numberBtn.tag = 30000+ i;
        
        [numberBtn setTitle:[NSString stringWithFormat:@"%ld",model.questionNumber] forState:UIControlStateNormal];
        
        [bgView addSubview:numberBtn];
        
        [numberBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.centerY.equalTo(bgView);
            make.width.height.mas_equalTo(35);
        }];
    }
}

- (void)setNumbersWithRows:(NSInteger)rows withMultiple:(NSArray *)Multiple withSingleRows:(NSInteger)singleRows {
    for (int i = 0; i< rows; i++) {
        UIView *bgView = [[UIView alloc] init];
        bgView.backgroundColor = [UIColor whiteColor];
        CGFloat a = i/5.;
        NSInteger b = i/5+1;
        NSInteger row = a>b? b: b-1;
        
        bgView.frame = CGRectMake(kSCREEN_WIDTH/5*(i%5), kSCREEN_WIDTH/5*row, kSCREEN_WIDTH/5, kSCREEN_WIDTH/5);
        [self.contentView addSubview:bgView];
        
        UIButton *numberBtn;
        
        ZLExamResultListModel *model = (ZLExamResultListModel *)Multiple[i];

        numberBtn = [self getNumberLblWithType:model.typeOfAnswer];

        numberBtn.tag = 30000+i+singleRows;
        
        [numberBtn setTitle:[NSString stringWithFormat:@"%ld",model.questionNumber] forState:UIControlStateNormal];

        [bgView addSubview:numberBtn];
        
        [numberBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.centerY.equalTo(bgView);
            make.width.height.mas_equalTo(35);
        }];
    }
}


- (UIButton *)getNumberLblWithType:(NSString *)type {
    UIButton *numberBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    numberBtn.layer.cornerRadius = 17.5;
    numberBtn.layer.masksToBounds = YES;
    [numberBtn addTarget:self action:@selector(buttonClickAction:) forControlEvents:UIControlEventTouchUpInside];
    
    if (type.integerValue == 1) {
//        numberBtn.layer.backgroundColor = [[UIColor whiteColor] CGColor];
//        [numberBtn setTitleColor:[UIColor darkGrayColor] forState:UIControlStateNormal];
//        numberBtn.layer.borderColor = [[UIColor darkGrayColor] CGColor];
//        numberBtn.layer.borderWidth = 0.5;
        numberBtn.layer.backgroundColor = [kMY_BLUE_COLOR CGColor];
        [numberBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    } else if (type.integerValue == 2) {
        numberBtn.layer.backgroundColor = [kRGB_COLOR(237, 40, 46, 1) CGColor];
        [numberBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    } else {
        numberBtn.layer.backgroundColor = [kMY_BLUE_COLOR CGColor];
        [numberBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    }
    
    return numberBtn;
}

@end
